package com.dao;

import java.sql.*;

/**
 * 测试数据插入
 * @author zyf
 */
public class InsertDataTest {
    public static void main(String[] args) {
        BaseDao base = new BaseDao("conf/database.properties");
//        baseDao.setPropsPath("conf/database.properties");
//        BaseDao base = baseDao.getInstance();
//        Connection conn = base.getConnection();
        Connection conn = base.getConnectionFromDruid();
        String blockSql = "INSERT INTO Block values (?,?,?,?,?)";
        String tranSql = "INSERT INTO Transaction values (?,?,?,?,?,?,?)";
        PreparedStatement blockPstmt = null;
        PreparedStatement tranPstmt = null;
        Timestamp timestamp = new Timestamp(new java.util.Date().getTime());
        try {
            blockPstmt = conn.prepareStatement(blockSql);
//            blockPstmt.setNString(1,"2");
            blockPstmt.setString(1,"hashhash");
            blockPstmt.setString(2,"prehash");
            blockPstmt.setInt(3, 2);
            blockPstmt.setInt(4, 2);
            blockPstmt.setTimestamp(5, timestamp);
            int blockRs = blockPstmt.executeUpdate();
            System.out.println(blockRs);
            tranPstmt = conn.prepareStatement(tranSql);
//            tranPstmt.setNString(1,"1");
            tranPstmt.setString(1,"trtrtrtr");
            tranPstmt.setInt(2,2);
            tranPstmt.setString(3,"cidcid");
            tranPstmt.setString(4,"transfer");
            tranPstmt.setString(5,"args");
            tranPstmt.setString(6,"blockid");
            tranPstmt.setTimestamp(7,timestamp);
            int tranRs = tranPstmt.executeUpdate();
            System.out.println(tranRs);
            base.closeAll(conn, blockPstmt);
            base.closeAll(conn, tranPstmt);
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            try {
                base.closeAll(conn, blockPstmt);
                base.closeAll(conn, tranPstmt);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
